function editTr(trId) {
    $("#" + trId).parent().children().each(function () {
        $(this).removeClass("success");
    });
    $("#" + trId).addClass("success");
    $("#" + trId + " input").each(function () {
        try {
            var id = $(this).attr("id");
            var idSplit = id.split("_");
            var inJq = $("#" + idSplit[0] + "_" + idSplit[1]);
            var tagName = inJq[0].tagName.toLowerCase();
            if (tagName == 'select') {
                inJq.combobox("select", $(this).val());
            } else {
                inJq.attr("value", $(this).val());
            }
        } catch (e) {

        }
    });

    $("#" + trId + " select").each(function () {
        var id = $(this).attr("id");
        var idSplit = id.split("_");
        $("#" + idSplit[0] + "_" + idSplit[1]).combobox("select", $(this).val());

    });

}

function delTr(trId) {
    var hglock = $("#HGISLOCK").val();
    var jylock = $("#JYISLOCK").val();
    if (hglock == "1" || jylock == "1") {
        $.messager.alert('提示', "该数据已经锁住不能删除");
        return;
    }
    $("#" + trId).remove();
    if (event.stopPropagation) {
        event.stopPropagation();
    } else {
        event.cancelBubble = true;
    }
}

function updateTr(input_trID, serid, parentSerId, trId) {
    var addParent = "";
    if (strIsNotBlank(parentSerId)) {
        addParent = "_" + parentSerId;
    }
    $("#" + input_trID + " input,#" + input_trID + " select").each(function () {
        var id = $(this).attr("id");
        if (id != null && ("" + id).indexOf("_")) {
            var idSplit = id.split("_");
            var updateInputId = idSplit[0] + "_" + idSplit[1] + "_" + serid + addParent;
            if ($("#" + updateInputId)) {
                $("#" + updateInputId).attr("value", $(this).val());
                $("#" + updateInputId).parent().parent().removeClass("success");
            }
        }
    });
}

function addTr(contentId, serid, namePre, parentSerId) {
    var trHtml = "";
    var inputSorts = new Array();
    var parentId = "";
    if (strIsNotBlank(parentSerId)) {
        parentId = "_" + parentSerId;
    }
    $("#" + contentId + " input[showIndex]").each(function () {
        var id = $(this).attr("id");

        var fieldName = getFieldName(namePre, $(this).attr("fieldName"));

        var showIndex = $(this).attr("showIndex");
        var value = $(this).val();
        var isHidden = 1;
        if ("" + showIndex != "0") {
            isHidden = 0;
        }
        var newInput = getInput(id + "_" + serid + parentId, fieldName, value, isHidden, "");

        if (isHidden == 0) {
            inputSorts[showIndex] = newInput;
        } else {
            trHtml += newInput;
        }
    });

    $("#" + contentId + " select[showIndex]").each(function () {
        var id = $(this).attr("id");
        var fieldName = getFieldName(namePre, $(this).attr("fieldName"));
        var showIndex = $(this).attr("showIndex");
        var option = $(this).find("option:selected");
        var isHidden = 1;
        if ("" + showIndex != "0") {
            isHidden = 0;
        }
        trHtml += getInput(id + "_" + serid + parentId, fieldName, $(this).val(), 1, "");
        if (isHidden == 0) {
            inputSorts[showIndex] =
                getInput(id + "mc_" + serid + parentId, "", option.text(), isHidden, "");
        }
    });

    for (var inputSortsIndex = 0; inputSortsIndex < inputSorts.length; inputSortsIndex++) {
        var inputHtml = inputSorts[inputSortsIndex];
        if (inputHtml != null && inputHtml != "" && ("" + inputHtml) != "undefined") {
            trHtml += "<td>" + inputHtml + "</td>";
        }
    }
    return trHtml;
}

function strIsNotBlank(value) {
    var result = 0;
    if (value && "" + value != "") {
        result = 1;
    }
    return result;
}
function getFieldName(namePre, fieldName) {
    var result = "";
    if (fieldName != null && "" + fieldName != "undefined" && "" + fieldName != "") {
        result = namePre + fieldName;
    }
    return result;
}

function getInput(id, name, value, isHidden, styleValue) {
    value = value.replace(/["]/g, '&#34;');
    //value = value.replace('"', '&#34;');
    var result = '<input style="' + styleValue + '" size="10"  id="' + id + '" name="' + name
                 + '" value="' + value + '"';
    if (isHidden == 1) {
        result += "type='hidden'";
    }
    result += " readonly='readonly' />";
    return result;
}
